home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / haiku.lwm < prev    next >
Text File  |  1993-12-13  |  11KB  |  348 lines

  1. /* A haiku generator CMD: Haiku
  2.  * from "Using ARexx on the Amiga" by Sullivan and Zamara */
  3. /* Adapted By Arnie */
  4. /* Encrufted by Robert */
  5. /* Tue Dec  1 22:45:53 1992 */
  6.  
  7. signal on error
  8. signal on syntax
  9. call InitVocab()
  10. call random(,,time('s'))
  11.  
  12. call addlib "LWModelerARexx.port", 0
  13. Continue=1
  14. do while Continue
  15.    Continue= GenHaiku()
  16.    end
  17.  
  18. say 'Exiting...'
  19.  
  20. exit
  21.  
  22.  
  23. /* GenHaiku
  24.  
  25.    Generate and return a single Haiku poem
  26. */
  27. GenHaiku:
  28.    /* Select a template, parse it into 3 lines, and clear output buffer. */
  29.    t = random(1,num_templates)
  30.    parse var tem.t line.1 '+' line.2 '+' line.3
  31.    out. = ''
  32.    
  33.    /* Process template lines one at a time. */
  34.    do i=1 to 3
  35.    
  36.       /* Keep going till template line exhausted. */
  37.       do while length(line.i) > 0
  38.          parse var line.i cmd 3 qual 4 line.i
  39.    
  40.          c = left(cmd, 1)
  41.          ucmd = upper(cmd)
  42.  
  43.          if v.ucmd ~= "" then do
  44.             w = word(v.ucmd, random(1, words(v.ucmd)))
  45.    
  46.             if datatype(c, 'u') then
  47.                w = upper(left(w, 1))substr(w, 2)
  48.  
  49.             upper c
  50.  
  51.             if c='V' & qual='@' then
  52.                w = add_ing(w)
  53.             else if c='N' & qual='s' then
  54.                w = pluralize(w)
  55.             else
  56.                line.i = qual || line.i
  57.  
  58.             end
  59.          else if c='/' then do
  60.             parse value cmd || qual || line.i with '/' list '/' line.i
  61.             w = word(list, random(1, words(list)))
  62.             end
  63.          else
  64.             parse value cmd || qual || line.i with w 2 line.i
  65.  
  66.          out.i = out.i || w
  67.          end
  68.       end
  69.       out.1=translate(out.1,' ','_')
  70.       out.2=translate(out.2,' ','_')
  71.       out.3=translate(out.3,' ','_')
  72.       say
  73.       say out.1  /* Redirect rx output to file */
  74.       say out.2  /* To capture Haikus to file */
  75.       say out.3  /* i.e. RX >>S:Haiku.Log Haiku.lwm  */
  76.       say
  77.    return notify(2,'!'out.1, '!'out.2, '!'out.3,'@Another?')
  78.  
  79.  
  80. /* Add_Ing
  81.  
  82.    Add the `ing' suffix to the given verb. The trick here is to double
  83.    the final consonant of the verb in many but not all instances. The
  84.    exception list and the code that employs take care of this. When new
  85.    verbs are added to the vocabulary lists, consider whether the `ing'
  86.    form is exceptional.
  87. */
  88. add_ing: procedure
  89.  
  90.    exc. = 0
  91.    exc.withdraw = 1
  92.    exc.wander  = 1
  93.    exc.snarf   =1
  94.    exc.wallow  = 1
  95.    exc.flicker = 1
  96.    exc.shiver  = 1
  97.    exc.wonder  = 1
  98.    exc.edit  = 1
  99.    exc.render  = 1
  100.    exc.pay  = 1
  101.    exc.eat  = 1
  102.    exc.walk = 1
  103.    exc.shoot = 1
  104.    exc.fling = 1
  105.    exc.speak = 1
  106.    exc.flow = 1
  107.    exc.crawl = 1
  108.    exc.creep = 1
  109.    exc.reek = 1
  110.    exc.sink = 1
  111.    exc.croak = 1
  112.    exc.burn = 1
  113.    exc.stink = 1
  114.    exc.steal = 1
  115.    exc.peel = 1
  116.    exc.kill = 1
  117.    exc.toast = 1
  118.    exc.rent = 1
  119.    exc.drink = 1
  120.    exc.Smooth = 1
  121.    exc.Load = 1
  122.    exc.Stretch = 1
  123.    exc.Clear = 1
  124.    exc.Patch = 1
  125.    exc.Morph = 1
  126.    exc.destroy = 1
  127.    exc.accept = 1
  128.    exc.reboot = 1
  129.    exc.despair = 1
  130.    exc.descend = 1
  131.    exc.command = 1
  132.    exc.broadcast = 1
  133.    exc.shiver = 1
  134.    exc.Jitter = 1
  135.    exc.Mirror = 1
  136.    exc.Bevel = 1
  137.    exc.Align = 1
  138.    exc.encruft = 1
  139.    exc.command = 1
  140.    exc.splatter = 1
  141.    exv  = upper(arg(1))
  142.  
  143.    parse value arg(1) with 100 -3 l3 +1 l2 +1 l1
  144.  
  145.    if index("mbgprndlt",l1)>0 & index("aeiou",l2)>0 & index("aeiou",l3)=0 then do
  146.       if ~exc.exv then
  147.          w = arg(1) || l1
  148.       else
  149.          w = arg(1)
  150.       end
  151.    else if l1='e' then
  152.       w = left(arg(1), length(arg(1)) - 1)
  153.    else
  154.       w = arg(1)
  155.  
  156.    return w || 'ing'
  157.  
  158.  
  159. /* Pluralize
  160.  
  161.    Pluralize the given word, taking account of certain exceptions. If you
  162.    add nouns to the vocabulary lists, consider whether the pluralization
  163.    is exceptional.
  164. */
  165. pluralize: procedure expose v.
  166.  
  167.    exc. = 0
  168.    exc.ice  = 1
  169.    exc.beach   = 1
  170.    exc.spooge  = 1
  171.    exc.kluge  = 1
  172.    exc.mouse   = 1
  173.    exc.moose   = 1
  174.    exc.bass    = 1
  175.    exc.box     = 1
  176.    exc.peach   = 1
  177.    exc.glance  = 1 
  178.    exc.bus     = 1
  179.    exc.juice   = 1
  180.    exc.paintbox = 2
  181.    exc.Image   = 2
  182.    exc.Sequence = 2
  183.    exc.lotus   = 2
  184.    exc.gecko   = 10
  185.    exc.cry     = 11
  186.    exc.dei     = 12
  187.  
  188.    w  = arg(1)
  189.    uw = upper(w)
  190.  
  191.    /* Nouns with an exception code of 1 or 2 have 1 or 2 syllables
  192.       respectively in the singular, but an extra syllable in the plural.
  193.       Since the syllables must remain constant, we replace such a noun
  194.       with another from its list, until we find one that is not lengthened
  195.       by pluralization.
  196.    */
  197.    do while exc.uw > 0 & exc.uw < 10
  198.       list = value('v.n'exc.uw)
  199.       w    = word(list, random(1, words(list)))
  200.       uw   = upper(w)
  201.       end
  202.  
  203.    /* Match capitalization of argument word with (possibly) new word. */
  204.    if datatype(left(arg(1),1),'u') then
  205.       w = upper(left(w,1))substr(w,2)
  206.  
  207.    /* Pluralize */
  208.    select
  209.       when exc.uw =  0 then w = w || 's'
  210.       when exc.uw = 10 then w = w || 'es'
  211.       when exc.uw = 11 then w = left(w,2) || 'es'
  212.       otherwise
  213.          call inform("Invalid pluralize exception" exc.uw)
  214.          exit
  215.       end
  216.  
  217.    return w
  218.  
  219.  
  220. InitVocab:
  221.  
  222. v. = ""
  223.  
  224. /* Adjectives, one syllable */
  225. av.a1 = "quick wild small hot white wet blue pink old light dark"
  226. v.a1 = v.a1 "sad deep lost free drunk slow dumb hard soft damp dry"
  227. v.a1 = v.a1 "tight loose gross cold clean proud dead plaid munged nuked"
  228. v.a1 = v.a1 "strong weak young dull ill mean flat sharp kluged tweaked"
  229.  
  230. /* Adjectives, two syllables */
  231. v.a2 = "evil putrid empty crooked runny fallen dismal crufty"
  232. v.a2 = v.a2 "potent rabid gnarly golden hairy wrinkled cuspy"
  233. v.a2 = v.a2 "robust rancid smiling toasted paisley dying measly"
  234. v.a2 = v.a2 "brain_dead stupid plastic bogus lo-res frothy 3D hi-res"
  235. v.a2 = v.a2 "opaque diffuse default wireframe print-res angry flattened"
  236.  
  237.  
  238. /* Nouns, one syllables */
  239. v.n1 = "goat moose cat stream kluge fade mouse sprite bomb bass disc box"
  240. v.n1 = v.n1 "worm hack moon dog glance flame spooge cow pig shell cone Fudd"
  241. v.n1 = v.n1 "frob Spam curve spline clone duck sea hand fish neck growth ice"
  242. v.n1 = v.n1 "point sync deck cop food RAM wine beer car bus bike juice ball"
  243. v.n1 = v.n1 "box light scene key bone frame fog sky ground view stat Duff"
  244.  
  245.  
  246. /* Nouns, two syllables */
  247. v.n2 = "shadow forest guitar keyboard missile toaster teapot pointer guru"
  248. v.n2 = v.n2 "ooblick chomper dissolve parrot budgie info volume red_head"
  249. v.n2 = v.n2 "CD valley switcher cookie framestore farmer hard_disk wetware"
  250. v.n2 = v.n2 "Toaster LightWave model object cheese_shop option splitter"
  251. v.n2 = v.n2 "CG starship airport sports_car pudding oatmeal layout weasel wirehead"
  252. v.n2 = v.n2 "image preview shadow bump_map color segment motion widget"
  253. v.n2 = v.n2 "lens_flare spot_light backdrop zenith nadir program hacker"
  254.  
  255.  
  256. /* Verbs, one syllable */
  257. v.v1 = "walk eat grab shoot fling frag stick speak flow live cut paste"
  258. v.v1 = v.v1 "rip crawl creep reek bite sink take croak burn stop stink flip"
  259. v.v1 = v.v1 "spit shine steal fade peel crave kill stab writhe split"
  260. v.v1 = v.v1 "dub toast tape cut rent burn shop chomp pay drink eat snore"
  261. v.v1 = v.v1 "make smooth load save clear lathe blast ride"
  262. v.v1 = v.v1 "clone skin morph grok mung phreak count nuke snarf"
  263.  
  264. /* Verbs, two syllables */
  265. v.v2 = "explode desire adlib destroy decline accept dissolve endure reboot"
  266. v.v2 = v.v2 "rebel retire despair encode wonder bubble flicker grumble"
  267. v.v2 = v.v2 "decode descend compile command render edit broadcast shiver wallow"
  268. v.v2 = v.v2 "jitter combine copy bevel rotate splatter command withdraw"
  269. v.v2 = v.v2 "align extrude mirror flatline encruft guru"
  270.  
  271. /* Verbs, one syllable, transitive */
  272. v.v3 = "eat grab shoot cut rip bite sink take burn stop flip steal peel crave"
  273. v.v3 = v.v3 "stab split scream toast chomp drink save blast ride clone mung"
  274. v.v3 = v.v3 "snarf nuke kill find own lose keep know see smell hear taste feel"
  275.  
  276. /* Verbs, one syllable, transitive, past tense */
  277. v.t1 = "ate killed shot cut bit sank burned stopped stole found lost smashed" 
  278. v.t1 = v.t1 "chomped drank munged nuked snarfed took" 
  279.  
  280. /* Prepositions, one syllable */
  281. v.p1 = "on of in near past at by in through from"
  282.  
  283. /* Prepositions, two syllables */
  284. v.p2 = "left_of upon under beside over west_of beyond above below around"
  285. v.p2 = v.p2 "inside outside next_to far_from behind"
  286.  
  287. /* Relative adverbs, one syllable */
  288. v.r1 = "where when while as"
  289.  
  290. /* Little words that can precede nouns, biased towards `the' */
  291. v.l1 = "the God's Hell's this my Bob's your his her the Ken's Ron's Moe's"
  292. v.l1 = v.l1 "Skell's Mark's Paul's Tim's James' Dawn's Penn's its our the Wil's"
  293. v.l1 = v.l1 "Kirk's Spock's Worf's Q's Croooow's Joel's Bart's "
  294. v.l1 = v.l1 "Death's Jud's Dan's Dick's some all Ren's Charles' Anne's Steve's"         
  295.  
  296. /* Names, two syllables */
  297. v.h2 = "Robert NewTek Pink_Floyd Tami Smithers Billy Flanders"
  298. v.h2 = v.h2 "David Yoko Kiki Arnie Satan Jesus Homer Kerri Barney"
  299. v.h2 = v.h2 "Ervin Batman Robin Mofo some_jerk James_Bond"
  300. v.h2 = v.h2 "Kiki Simone Lobo Ayn_Rand John_Cleese Elvis Allen"
  301. v.h2 = v.h2 "Peter Kenbe Junior Daniel Teller Kristy Kelly Stuart"
  302. v.h2 = v.h2 "Dana Picard Riker Data Geordi Crusher Milhouse Apu Laura Tammy"
  303. v.h2 = v.h2 "Cambot Gypsy Alex Bobbi Lisa Maggie Porter Stephen Mojo Stimpy"
  304.  
  305. /* Haiku templates
  306.  
  307.    The special tokens in the templates are:
  308.  
  309.    a1,n2 etc.     Part of speech, replaced randomly from corresponding list
  310.    A1,N2 etc.     Same, but with initial capital
  311.    +              Converted to linefeed
  312.    @              After verb, specifies conversion to `ing' (gerund) form
  313.    s              After noun, specifies conversion to plural form
  314.    /wordlist.../  Replaced by a word picked randomly from the list
  315.  
  316.    All other symbols in the templates are taken literally.
  317. */
  318. tem.  = ""
  319. tem.1 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
  320. tem.2 = "P2 the a1 n1,+R1 the a2 n2 v1s,+I v1; the n1 v1s."
  321. tem.3 = "The a1 n1 v1@;+It is the a2 n2.+V2@, I v1."
  322. tem.4 = "The a2 n1 v1s+R1 a2 n2s v2.+Does the a1 n1 v1?"
  323. tem.5 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  324. tem.6 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
  325. tem.7 = "/Never Sometimes/ a1, but a1,+H2 knows /no my some all/ a1 n2s.+A2, /he she/ v2s."
  326. tem.8 = "/Not Quite/ a1, /and but or/ a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  327. tem.9 = "A1 n1, a2 n1.+L1 a1, a2 n2 v1s.+A1 n1, a1 n2."
  328. tem.10 = "The a2 n1 v1s +R1 a2 n2s v2.+Does the a1 n1 v1?"
  329. tem.11 = "Not a1, but a2,+H2 comes to the n2.+L1 a1 n2 v1s."
  330. tem.12 = "A1, a2, a2,+H2 v1s. H2 v2s,+V2@, v1@."
  331. tem.13 = "Hey! Get back to work +You lazy, no good n2. +The world is v1@!"
  332. tem.14 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you." 
  333. tem.15 = "If n2s could v1, +And v3 l1 n2 today, +The n1 would v3 you." 
  334. tem.16 = "As the n1 draws near, +H2 v3s our n1. You must +V3 the a1 n2." 
  335. tem.17 = "Alone the a1 n1 v1s. +'Where is my n2?', you ask. +/Ack! Doh! Oops!/ H2 t1 it." 
  336. tem.18 = "Attention all n1s! +When v1@ n2s v2, +It's time to v2." 
  337.  
  338. do i=1 while tem.i ~= ""
  339.    end
  340.  
  341. num_templates = i - 1
  342.  
  343. return
  344.  
  345. syntax:
  346. error:
  347.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  348.     exit